/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.entity;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.tenant.mp.TenantEntity;
import org.springblade.modules.admin.vo.contract.ContractBuildingInfoVo;
import org.springblade.modules.admin.vo.contract.ContractExtVo;

import java.sql.Struct;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 项目合同信息实体类
 *
 * @author ysq
 * @since 2022-03-01
 */
@Data
@TableName(value = "blade_building_contract_plus", autoResultMap = true)
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "BuildingContractPlus对象", description = "项目合同信息")
public class BuildingContractPlus extends TenantEntity {

	private static final long serialVersionUID = 1L;


	/**
	 * 项目名称逗号分割-冗余字段(用于列表查询)
	 */
	@ApiModelProperty(value = "项目名称逗号分割-冗余字段(用于列表查询)")
	@TableField(typeHandler = FastjsonTypeHandler.class)
	private List<ContractBuildingInfoVo> buildingInfo;

	/**
	 * 合同编码
	 */
	@ApiModelProperty(value = "合同编码")
	private String contractNo;
	/**
	 * 合同来源	1:新签	2:续签	3:转签	4:丢失	5:夺回	6:新梯移交	7:免保转签
	 */
	@ApiModelProperty(value = "合同来源	1:新签	2:续签	3:转签	4:丢失	5:夺回	6:新梯移交	7:免保转签")
	private Integer contractSource;
	/**
	 * 庸与字段(用于列表刷选)	合同类型	1:保养合同	2:委托合同	3:质保合同	4:维系合同
	 */
	@ApiModelProperty(value = "庸与字段(用于列表刷选)	合同类型	1:保养合同	2:委托合同	3:质保合同	4:维系合同,5保养赠送")
	private Integer contractType;
	/**
	 * 客户单位
	 */
	@ApiModelProperty(value = "客户单位")
	private String customerUnit;

	@ApiModelProperty(value = "客户单位id")
	private Long customerUnitId;
	/**
	 * 客户电话
	 */
	@ApiModelProperty(value = "客户电话")
	private String customerPhone;

	/**
	 * 客户电话
	 */
	@ApiModelProperty(value = "安装队信息")
	@TableField(exist = false)
	private String azPhone;

	/**
	 * 维保单位
	 */
	@ApiModelProperty(value = "维保单位")
	private String maintainUnit;
	/**
	 * 维保主要负责人-签约人
	 */
	@ApiModelProperty(value = "维保主要负责人-签约人ID")
	private Long maintainMainUser;

	/**
	 * 维保主要负责人-签约人
	 */
	@ApiModelProperty(value = "维保主要负责人-签约人名称")
	@TableField(exist = false)
	private String maintainMainUserName;


	/**
	 * 合同开始时间
	 */
	@ApiModelProperty(value = "合同开始时间")
	private Date contractBeginTime;
	/**
	 * 合同结束时间
	 */
	@ApiModelProperty(value = "合同结束时间")
	private Date contractEndTime;
	/**
	 * 合同状态1:未生效2:已生效3:已到期4:已终止
	 */
	@ApiModelProperty(value = "合同状态1:未生效2:已生效3:已到期4:已终止")
	private Integer contractStatus;
	/**
	 * 保养类型	1:清包	2:半包	3:全包	4:三包	5:小包	6:免包	7:维修
	 */
	@ApiModelProperty(value = "保养类型	1:清包	2:半包	3:全包	4:三包	5:小包	6:免包	7:维修")
	private Integer maintainType;
	/**
	 * 是否需要驻场0:不需要1：需要
	 */
	@ApiModelProperty(value = "是否驻点: 1-不限，2-驻点")
	private Integer isLive;
	/**
	 * 年检费用
	 */
	@ApiModelProperty(value = "年检费用")
	private String yearCostDesc;
	/**
	 * 月保养费用
	 */
	@ApiModelProperty(value = "月保养费用")
	private String monthCostDesc;
	/**
	 * 限速器年检费用
	 */
	@ApiModelProperty(value = "限速器年检费用")
	private String yearSpeedGovernorCost;

	@ApiModelProperty(value = "合同金额")
	private String contractCost;
	/**
	 * 支付方式	1:月结	2:两月结	3:季度结	4:四月结	5:半年结	6:年度结	7:预付50%	8:完结50%	9:一次性付款	10:免费
	 */
	@ApiModelProperty(value = "支付方式	1:月结	2:两月结	3:季度结	4:四月结	5:半年结	6:年度结	7:预付50%	8:完结50%	9:一次性付款	10:免费")
	private Integer payDateDesc;
	/**
	 * 付款周期	1:周期结束时付款	2:周期中期时付款	3:周期开始时付款
	 */
	@ApiModelProperty(value = "付款周期	1:周期结束时付款	2:周期中期时付款	3:周期开始时付款")
	private Integer payDateType;
	/**
	 * 发票类型	1:增值税专用发票	2:增值税普通发票	3:收据	4:已收款未开票	5:已开收据为付款	6:已开收据未开发票	7：预支发票	8：其它
	 */
	@ApiModelProperty(value = "发票类型	1:增值税专用发票	2:增值税普通发票	3:收据	4:已收款未开票	5:已开收据为付款	6:已开收据未开发票	7：预支发票	8：其它")
	private Integer invoiceType;
	/**
	 * 支付方式	1:支票	2:现金	3:电汇	4:成若电汇
	 */
	@ApiModelProperty(value = "支付方式	1:支票	2:现金	3:电汇	4:成若电汇")
	private Integer payType;

	@ApiModelProperty("payDateDesc-选择7和8有值")
	private Date payBeginDate;

	private Date payEndDate;

	/**
	 * 合同附件地址,数组
	 */
	@ApiModelProperty(value = "合同附件地址,逗号分割")
	@TableField(typeHandler = FastjsonTypeHandler.class)
	private List<ContractExtVo> contractExt;


	@ApiModelProperty(value = "审核人")
	private String auditorName;

	@ApiModelProperty(value = "回收站true表示加入回收站")
	private Boolean disDeleted;

	private Integer yearSpeedGovernorCostType;

	private Integer yearCostType;

	private String contractDesc;

	@ApiModelProperty(value = "合同归属1:外包合同 2:非外包合同")
	private Integer fromType;


	@ApiModelProperty(value = "上级合同id")
	private Long parentId;

	@ApiModelProperty(value = "合同终止时间")
	@TableField(updateStrategy = FieldStrategy.IGNORED)
	private Date stopTime;

	/**
	 * 合同扩展状态
	 * 1:待续签
	 * 2:已续签
	 * 3:即将到期
	 * 4:已脱保
	 * 5:已作废
	 */
	@ApiModelProperty(value = "合同扩展状态")
	private Integer contractExtStatus;

	@ApiModelProperty(value = "审核状态描述")
	private String statusDesc;


	@ApiModelProperty("更新时间")
	private Date updateTime;

	@ApiModelProperty("更新人")
	private Long updateUser;

	@ApiModelProperty("是否质保合同0:否，1是,-1表示无状态")
	private Integer isQuaGuarantee;

	@ApiModelProperty("脱保时间")
	private Date tuoDate;

	@ApiModelProperty("脱保类型1:服务不达标2:竞对签约3:客户暂停使用电梯-1:其他")
	private Integer tuoType;

	@ApiModelProperty("脱保类型其他描述")
	private String tuoTypeDesc;

	@ApiModelProperty("审核时间")
	private Date checkTime;

	@ApiModelProperty("审核人id")
	private Long checkUserId;

	@ApiModelProperty("超出合同结束时间多少天")
	private Integer endDay;

	@ApiModelProperty("距离合同结束时间多少天")
	private Integer aboutEndDay;

	@ApiModelProperty("未审核超出多少天")
	private Integer disCheckDay;

	@ApiModelProperty("是否变更1:已经变更0:未变更")
	private Integer changeType;

	@ApiModelProperty("变革时间")
	private Date changeTime;

	@ApiModelProperty("合同附件")
	@TableField(exist = false)
	private BuildingContractExtPlus buildingContractExtPlus;

	@TableField(exist = false)
	private Boolean isUpdate = false;


	@ApiModelProperty("旧数据")
	@TableField(exist = false)
	private BuildingContractPlus oldBuildingContractPlus;

	@ApiModelProperty("编辑修改类型 1:默认编辑修改2:重新提交修改")
	@TableField(exist = false)
	private Integer updateType = 1;


	@ApiModelProperty("创建人")
	@TableField(exist = false)
	private String createUserName;

	@ApiModelProperty("每页的数量")
	@TableField(exist = false)
	private Integer buildingInfoCounts;

	@ApiModelProperty("创建时间")
	@TableField(exist = false)
	private Integer createDate;


	@ApiModelProperty("合同电梯总数量")
	@TableField(exist = false)
	private Integer elevatorCounts = 0;

	@ApiModelProperty("单个项目电梯数量")
	@TableField(exist = false)
	private Integer buildingElevatorCounts = 0;


	@ApiModelProperty("电梯在保合同状态")
	@TableField(exist = false)
	private Integer maintainStatus;


	@ApiModelProperty("协议id")
	@TableField(exist = false)
	private Long agreeId;


	@ApiModelProperty(value = "上级合同编号")
	@TableField(exist = false)
	private String parentNo;


	@ApiModelProperty(value = "维保主要负责人-签约人名称在职状态")
	@TableField(exist = false)
	private Integer userStatus;

	@ApiModelProperty(value = "品牌名称")
	@TableField(exist = false)
	private String brandNames;

	public void setMaintainStatus(String maintainStatus) {
		if (StrUtil.isNotEmpty(maintainStatus)) {
			this.maintainStatus = Convert.toInt(maintainStatus.split(",")[0]);
		} else {
			this.maintainStatus = Convert.toInt(maintainStatus);
		}
	}

	public void setBuildingInfo(List<ContractBuildingInfoVo> buildingInfo) {
		List<ContractBuildingInfoVo> list = new ArrayList(16);
		for (int i = 0; i < buildingInfo.size(); i++) {
			ContractBuildingInfoVo contractBuildingInfoVo = JSON.parseObject(JSON.toJSONString(buildingInfo.get(i)), ContractBuildingInfoVo.class);
			list.add(contractBuildingInfoVo);
		}
		this.buildingInfo = list;
	}
}
